public class Main {
    public static void main(String[] args) {

    }
    int[] dx={0,0,1,-1,1,-1,1,-1};
    int[] dy={1,-1,0,0,1,-1,-1,1};
    int n,m;

    /**
     * 扫雷
     * @param board
     * @param click
     * @return
     */
    public char[][] updateBoard(char[][] board, int[] click) {
        n=board.length;
        m=board[0].length;
        dfs(board,click[0],click[1]);
        return board;
    }
    public void dfs(char[][] board,int i,int j){
        if(board[i][j]=='M'){
            board[i][j]='X';
            return;
        }
        if(board[i][j]=='E'){
            int count=0;
            for(int k=0;k<8;k++){
                int x=i+dx[k];
                int y=j+dy[k];
                if(x>=0&&x<n&&y>=0&&y<m&&board[x][y]=='M'){
                    count++;
                }
            }
            if(count<=0){
                board[i][j]='B';
                for(int k=0;k<8;k++){
                    int x=i+dx[k];
                    int y=j+dy[k];
                    if(x>=0&&x<n&&y>=0&&y<m&&board[x][y]=='E'){
                        dfs(board,x,y);
                    }
                }
            }else{
                board[i][j]=(char)(count+'0');
            }
        }
    }
}